1904A - Forked - CodeForces Solution


brute force

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#define ll long long int
#define unll unsigned long long
#define pb push_back
#define mp make_pair
#define         aff(v) for(auto e:v) cout<<e<<" ";cout<<endl;
#define f(i,j,k,l) for(ll i=j;i<k;i+=l)
typedef unsigned long long ull;
typedef long double db;
using namespace std;
const ll n=2e5+5;



string inverserChaine(const std::string& chaine) {
    string chaineInverse;
    for (int i = chaine.length() - 1; i >= 0; i--) {
        chaineInverse += chaine[i];
    }
    return chaineInverse;
}




void solve() {

    int y;cin>>y;
    while(y--){

            int a,b ;cin>>a;cin>>b;
            int xk,yk;cin>>xk;cin>>yk;
            int xq,yq;cin>>xq;cin>>yq;
            int xn,yn,xn1,yn1,xnn,ynn,xn11,yn11,xa,xaa,ya,yaa,xa1,xaa1,ya1,yaa1;
            set<pair<int, int>> m;
            //if(a>abs(xq-xk) && b>abs(yq-yk))cout<<"0"<<endl;
            if((xk==xq && abs(yk-yq)%2==0 && (a==abs(yk-yq)/2 ||b==abs(yk-yq)/2))||((yk==yq && abs(xk-xq)%2==0) &&(a==abs(xk-xq)/2 ||b==abs(xk-xq)/2))){
                    cout<<"2"<<endl;

            }
            else {

            set<pair<int, int>> s;
            // Calculate eight new positions and insert them into the set
            s.insert({xk + a, yk + b});
            s.insert({xk + a, yk - b});
            s.insert({xk + b, yk + a});
            s.insert({xk + b, yk - a});
            s.insert({xk - a, yk + b});
            s.insert({xk - a, yk - b});
            s.insert({xk - b, yk + a});
            s.insert({xk - b, yk - a});

            s.insert({xq + a, yq + b});
            s.insert({xq + a, yq - b});
            s.insert({xq + b, yq + a});
            s.insert({xq + b, yq - a});
            s.insert({xq - a, yq + b});
            s.insert({xq - a, yq - b});
            s.insert({xq - b, yq + a});
            s.insert({xq - b, yq - a});


            if(a==b){cout<<8-s.size()<<endl;}
            else cout<<16-s.size()<<endl;






            }







            }}





































 int main(){

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(false);
        cin.tie(0);



        solve ();
}


Comments

Submit
0 Comments
More Questions

380. Insert Delete GetRandom O(1)
332. Reconstruct Itinerary
368. Largest Divisible Subset
377. Combination Sum IV
322. Coin Change
307. Range Sum Query - Mutable
287. Find the Duplicate Number
279. Perfect Squares
275. H-Index II
274. H-Index
260. Single Number III
240. Search a 2D Matrix II
238. Product of Array Except Self
229. Majority Element II
222. Count Complete Tree Nodes
215. Kth Largest Element in an Array
198. House Robber
153. Find Minimum in Rotated Sorted Array
150. Evaluate Reverse Polish Notation
144. Binary Tree Preorder Traversal
137. Single Number II
130. Surrounded Regions
129. Sum Root to Leaf Numbers
120. Triangle
102. Binary Tree Level Order Traversal
96. Unique Binary Search Trees
75. Sort Colors
74. Search a 2D Matrix
71. Simplify Path
62. Unique Paths